package com.weilus.websocket;

import java.util.Date;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

@Controller
public class WebSocketController {
	public static final Logger log = LoggerFactory.getLogger(WebSocketController.class);
	@Autowired
	private SimpMessagingTemplate template;
    
    //客户端 发送消息
    @MessageMapping("/sendmsg")								
    public void test(Message message){
    	log.info("testmsg====>access_token:"+message.getAccess_token()+"      name:"+message.getName());
    	message.setUrl("http://www.baidu.com");
    	template.convertAndSendToUser(message.getTo(),"/message",message);
    }
    
    

    public static class Message{
    	private String from;
    	private String to;
    	private Date date = new Date();
    	private String url;
    	private String name;
    	private String access_token;
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getAccess_token() {
			return access_token;
		}
		public void setAccess_token(String access_token) {
			this.access_token = access_token;
		}
		public String getFrom() {
			return from;
		}
		public void setFrom(String from) {
			this.from = from;
		}
		public String getTo() {
			return to;
		}
		public void setTo(String to) {
			this.to = to;
		}
		public Date getDate() {
			return date;
		}
		public String getUrl() {
			return url;
		}
		public void setUrl(String url) {
			this.url = url;
		}
		
    }
}